# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

# 配置登录gitee的账号和密码信息（需修改为实际值）
USERNAME = "xxxxxxxxx@163.com"
PASSWORD = "xxxxxxx"

LOGIN_URL = "https://gitee.com/login"


def auto_get_gitee_traffic():
    # 初始化浏览器驱动（Chrome示例）
    options = webdriver.ChromeOptions()
    options.add_argument("--disable-infobars")  # 禁用信息栏
    options.add_argument("start-maximized")  # 最大化窗口

    driver = webdriver.Chrome(options=options)
    # 打开浏览器
    driver.get(LOGIN_URL)

    try:
        # 等待登录表单加载（根据实际页面调整选择器）
        WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.CSS_SELECTOR, '#user_login'))
        )

        # 输入用户名和密码（根据实际页面调整选择器）
        username_field = driver.find_element(By.ID, "user_login")  # 根据实际name或id修改
        password_field = driver.find_element(By.ID, "user_password")
        #
        username_field.send_keys(USERNAME)
        password_field.send_keys(PASSWORD)

        # 提交登录表单（查找登录按钮）
        login_button = driver.find_element(By.CSS_SELECTOR, "input[type=submit]")
        login_button.click()
    except Exception as e:
        print("操作失败:", str(e))
    finally:
        driver.quit()


if __name__ == "__main__":
    auto_get_gitee_traffic()
